"""
Triggers
Implements location-based events, or "triggers"
"""

# TODO: Implement individual triggers

import logging
from point import Point

class Trigger(object):
    """
    The simplest of triggers. Does a specific function when triggered.
    """
    log = logging.getLogger('pgame.engine.Trigger')
    
    def __init__(self, game, world, bounds, action):
        self.action = action
        self.game = game
        self.ocean = world
        self.ocean.append(self, bounds.center)
        self.bounds = bounds
        
    def collide(self, other):
        """
        This is the main trigger function. Executed when someone
        enters our trigger zone.
        """
        self.log.info('Trigger at %s fired' % self.bounds)
        self.action(other)

    def checkCollision(self, other):
        """
        Determine if we are colliding with other.
        """
        otherBounds = Point(*self.ocean.getCoord(other))
        return self.bounds.collision(otherBounds)


